package com.tucc.hello.leetcode.no1_400.no1_200.no81_100.no94;

import com.tucc.hello.tree.Main;
import com.tucc.hello.tree.TreeNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        TreeNode root = Main.makeTree(Arrays.asList(1, null, 2, 3));
        List<Integer> result = solution.inorderTraversal(root);
        System.out.println(result);
    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        inorderTraversal(root, result);
        return result;
    }

    public void inorderTraversal(TreeNode root, List<Integer> result) {
        if (root != null) {
            if (root.left != null) {
                inorderTraversal(root.left, result);
            }
            result.add(root.val);
            if (root.right != null) {
                inorderTraversal(root.right, result);
            }
        }

    }
}
